﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Smartec.Accounts.Camel.AMS.Model.Facades;
using Smartec.Accounts.Camel.AMS.Model.Entities;

namespace Smartec.Accounts.Camel.AMS.WebApp.Controllers
{
    [Authorize]
    public class AdminPartnersController : Controller
    {
        //
        // GET: /Partners/

        public ActionResult Index()
        {
            var Partners = PartnersFacade.GetAllPartners();
            return View(Partners);
        }

        //
        // GET: /Partners/Details/5

        public ActionResult Details(int id)
        {
            var Partner = PartnersFacade.GetPartnerById(id);
            return View(Partner);
        }

        //
        // GET: /Partners/Create

        public ActionResult Create()
        {
            return View();
        } 

        //
        // POST: /Partners/Create

        [HttpPost]
        public ActionResult Create(Partners partner )
        {
            try
            {
                // TODO: Add insert logic hereP
                PartnersFacade.AddPartners(partner);
                PartnersFacade.Save();
                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }
        
        //
        // GET: /Partners/Edit/5
 
        public ActionResult Edit(int id)
        {
            var Partner = PartnersFacade.GetPartnerById(id);
            return View(Partner);
        }

        //
        // POST: /Partners/Edit/5

        [HttpPost]
        public ActionResult Edit(int id, Partners Partner)
        {
            try
            {
                // TODO: Add update logic here
                PartnersFacade.UpdatePartners(Partner);
                PartnersFacade.Save();
                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }

        //
        // GET: /Partners/Delete/5
 
        public ActionResult Delete(int id)
        {
            var Partner = PartnersFacade.GetPartnerById(id);
            return View();
        }

        //
        // POST: /Partners/Delete/5

        [HttpPost]
        public ActionResult Delete(int id, FormCollection collection)
        {
            try
            {
                // TODO: Add delete logic here
                PartnersFacade.DeletePartnerById(id);
                PartnersFacade.Save();
                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }
    }
}
